#!/usr/bin/env ruby
# SPDX-License-Identifier: MulanPSL-2.0+
# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved.
# frozen_string_literal: true

require 'set'
require_relative '../defconfig.rb'

start_pod

names = Set.new %w[
  LOGGING_ES_HOST
  LOGGING_ES_PORT
  LOGGING_ES_USER
  LOGGING_ES_PASSWORD
]

authentication_info = relevant_service_authentication(names)

defaults = relevant_defaults(names)
defaults['LOGGING_ES_HOST'] ||= '172.17.0.1'
defaults['LOGGING_ES_PORT'] ||= '9202'
defaults.merge!(authentication_info)

env = docker_env(defaults)

docker_rm 'master-fluentd'

cmd = %w[
  docker run
  --restart=always
  --name master-fluentd
  -v /etc/localtime:/etc/localtime:ro
  -d
] + env + %w[
  -u 1090:1090
  -p 24224:24224/tcp
  -p 24224:24224/udp
  -e FLUENTD_CONF=docker-fluentd.conf
  --log-driver json-file
  --log-opt max-size=1g
  master-fluentd:alpine
]
cmd += ['sh', '-c', 'umask 002 & fluentd -c /fluentd/etc/docker-fluentd.conf']

system(*cmd)
